package com.qiqv.dto;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * @author hjr
 * @version 1.0
 * @date 2023/2/13 20:27
 */
@Data
public class QiQvResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 状态响应码
     */
    String responseCode;

    /**
     * 响应信息
     */
    String responseMsg;

    /**
     * 请求失败时的错误原因
     */
    String errorMsg;

    /**
     * 响应数据
     */
    T data;
    
    public static QiQvResult OK(Object data){
        QiQvResult result = new QiQvResult();
        result.setData(data);
        result.setResponseCode(ResultCodeEnum.SUCCESS.getCode());
        result.setResponseMsg(ResultCodeEnum.SUCCESS.getDescription());
        return result;
    }
    
    public static QiQvResult FAIL(String errorMsg){
        QiQvResult result = new QiQvResult();
        result.setResponseCode(ResultCodeEnum.UNEXPECTED_EXCEPTION.getCode());
        result.setErrorMsg(errorMsg);
        return result;
    }

    public static QiQvResult FAIL(String responseCode,String errorMsg){
        QiQvResult result = new QiQvResult();
        result.setResponseCode(responseCode);
        result.setErrorMsg(errorMsg);
        return result;
    }

    /**
     * 响应码枚举类
     */
    private enum ResultCodeEnum {

        SUCCESS("200","请求成功","success"),UNEXPECTED_EXCEPTION("500","服务端异常","server error,unexpected exception");

        private String code;

        private String description;

        private String description_ev;

        ResultCodeEnum(String code, String description, String description_ev) {
            this.code = code;
            this.description = description;
            this.description_ev = description_ev;
        }

        ResultCodeEnum() {
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getDescription_ev() {
            return description_ev;
        }

        public void setDescription_ev(String description_ev) {
            this.description_ev = description_ev;
        }
    }
}
